package cn.dlc.com.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

/**
 * @Author: dlc
 * @Date: 2021/11/24 - 16:40
 */
@Configuration
public class TokenConfig {

    /*@Bean
    public TokenStore tokenStore(){
        // 内存方式生成令牌
        return new InMemoryTokenStore();
    }*/

    // 使用jwt的方式存储令牌
    private String signing_key = "123_key";

    /**
     *
     * @return
     */
    @Bean
    public TokenStore tokenStore(){
        return new JwtTokenStore(accessTokenConverter());
    }

    @Bean
    public JwtAccessTokenConverter accessTokenConverter(){
        JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
        // 对称秘钥，资源服务通过该秘钥来验证
        converter.setSigningKey(signing_key);

        return converter;
    }
}
